$(function(){
    var imageId = null, remark = '', content = '', rid = '', status = null;
    // $('.confirm').click(function(){
    //     window.location.href = './show.html'
    // })
    $(".footer_buttons .prev_page").click(function () {
        window.history.go(-1);
    });
    $(".footer_buttons .next_page").click(function () {
        window.location.href = './home.html';
    });

    /*页面一进来获取图片识别结果*/
    var url = window.location.href;
    if (url.indexOf('imageId') != -1) {
        imageId = url.split('imageId=')[1];
        $.ajax({
            url: './i/home/image/getlastrecognition',
            type: 'POST',
            data: { imageId: parseInt(imageId)},
            error: function(error){},
            success: function(data) {
                if (data.error_code != 0) {
                    alert(data.error_msg)
                } else {
                    
                    /*成功后，更新图片*/
                    var $recognition_pic = $('.recognition_pic'), $origin_pic = $('.origin_pic');
                    $recognition_pic.css({
                        background: 'url(' + data.data.image_url + ') center top no-repeat',
                        backgroundSize: '100% 100%'
                    });
                    $origin_pic.css({
                        background: 'url(' + data.data.content + ') center top no-repeat',
                        backgroundSize: '100% 100%'
                    })
                    setTimeout(function(){
                        if (data.data.recognition_ret == 1) {
                            alert("未检测到TCFA斑块");
                        } 
                    },1000)
                    rid = data.data.id;
                    remark = data.data.ratification_content;
                    content = data.data.oppugn_content;
                    status = data.data.status;
                }
            }
        })
    } else {
        alert('没有图片Id，无法获取图像资源')
    }

    $('.confirm').click(function(){
        if (rid) {
            $.ajax({
                url: './i/home/image/ratification',
                type: 'POST',
                data: { rid: parseInt(rid), remark: remark},
                error: function(error) {

                },
                success: function(data) {
                    if (data.error_code != 0) {
                        alert(data.error_msg)
                    } else {
                        alert('图片认可成功，确定后页面跳转至上传页');
                        window.location.href = './show.html';
                        // if(status && (status == 2 || status ==4 || status==5 )) {
                        //     alert('图片认可成功，确定后页面跳转至上传页');
                        //     window.location.href = './show.html'
                        // } else {
                        //     if (status == 1) {
                        //         alert('识别中');
                        //     }
                        //     if (status == 3) {
                        //         alert('识别失败');
                        //     }
                            
                        // }
                    }
                }
            })
        } else {
            alert('没有图片rid，无法认可图片资源')
        }
    });
    $('.doubt').click(function () {
        if (rid) {
            window.location.href = './doubt.html?rid=' + rid;
        } else {
            alert('没有成功获取到图片的Id');
        }
    })

    
    

    // var container_width = $(".recognition_pic").width(), ratio = 2;
    // var lastHeight = container_width / ratio;
    // $('.recognition_pic').css({
    //     height: lastHeight
    // })
    // $(window).resize(function(){
    //     var container_width = $(".recognition_pic").width(), ratio = 2;
    //     var lastHeight = container_width / ratio;
    //     $('.recognition_pic').css({
    //         height: lastHeight
    //     })
    // })
    // var container_height = $(window).height()*0.75, ratio = 2;
    // var lastWidth = container_height * ratio, lastHeight = container_height;
    // $('.recognition_pic').css({
    //     height: lastHeight,
    //     width: lastWidth
    // })
    // $(window).resize(function () {
    //     var container_height = $(window).height() * 0.75, ratio = 2;
    //     var lastWidth = container_height * ratio, lastHeight = container_height;
    //     $('.recognition_pic').css({
    //         height: lastHeight,
    //         width: lastWidth
    //     })
    // })
})